var window = Ti.UI.createWindow({
	// orientationModes : [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT, Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT],
	backgroundColor : '#fff',
	width : Ti.UI.FILL,
	height : Ti.UI.FILL
});

var image = Ti.UI.createImageView({
	image : "data/images/icon_share.png",
	recognizeSimultaneously : "pinching,rotate",
	rotateGesture : true,
	pinchingGesture : true,
	panGesture : true,
	width : 54,
	height : 54,
	borderWidth : 1,
	borderColor : 'red'
});
var lastAngle = 0.0;
var currentAngle = 0.0;

var lastScale = 1.0;
var currentScale = 1.0;

var currentTranslation = {
	x : 0.0,
	y : 0.0
};
var lastTranslation = {
	x : 0.0,
	y : 0.0
};

function updateTransform(image) {
	var transform = Ti.UI.create2DMatrix().scale(lastScale * currentScale).rotate(lastAngle + currentAngle);

	transform.tx = lastTranslation.x + currentTranslation.x;
	transform.ty = lastTranslation.y + currentTranslation.y;

	image.transform = transform;
};

image.addEventListener('rotate', function(e) {
	currentAngle = e.rotation / Math.PI * 180.0;
	updateTransform(image);
});

image.addEventListener('rotateend', function(e) {
	lastAngle = (lastAngle + currentAngle) % 360.0;
	currentAngle = 0.0;
});

image.addEventListener('pinching', function(e) {
	currentScale = e.scale;
	updateTransform(image);
});

image.addEventListener('pinchingend', function(e) {
	lastScale = (lastScale * currentScale);
	currentScale = 1.0;
});

image.addEventListener('pan', function(e) {
	currentTranslation.x = e.translation.x;
	currentTranslation.y = e.translation.y;
	updateTransform(image);
});

image.addEventListener('panend', function(e) {
	lastTranslation.x = lastTranslation.x + currentTranslation.x;
	lastTranslation.y = lastTranslation.y + currentTranslation.y;
	currentTranslation.x = 0.0;
	currentTranslation.y = 0.0;
});

window.add(image);
window.open();

